﻿/**
 * @author: rayzhang
 */
#pragma once
#include "../libflow_global.h"
#include <QValidator>

class EprValidator : public QValidator { };

namespace flow
{
class LIBFLOW_API DoubleValidator : public QDoubleValidator
{
    Q_OBJECT

public:
    explicit DoubleValidator(double bottom      = std::numeric_limits<double>::lowest(),
                             double top         = std::numeric_limits<double>::max(),
                             int decimals       = 15,
                             bool fixFieldWidth = false,
                             QObject* parent    = nullptr);

    explicit DoubleValidator(int decimals, bool fixFiledWidth = false, QObject* parent = nullptr)
        : DoubleValidator(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max(), decimals, fixFiledWidth, parent) { }

    QValidator::State validate(QString& input, int& pos) const override;
    void fixup(QString& input) const override;

private:
    int _decimals = 0;
    bool _fixFieldWidth{false};
};

class LIBFLOW_API IntValidator : public QIntValidator
{
    Q_OBJECT

public:
    explicit IntValidator(QObject* parent = nullptr)
        : QIntValidator(std::numeric_limits<int>::min(), std::numeric_limits<int>::max(), parent) { }

    IntValidator(int bottom, int top, QObject* parent = nullptr)
        : QIntValidator(bottom, top, parent) { }

    // virtual QValidator::State validate(QString &input, int &pos) const;
    void fixup(QString& input) const override;
};
} // namespace flow
